﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using MySql.Data.MySqlClient;
namespace DAL
{
    public class regionDal
    {
        /// <summary>
        /// 通过等级查城市
        /// </summary>
        /// <param name="level"></param>
        /// <returns></returns>
        public static List<ms_region> Querybylevel(string level)
        {
            string sql = "select * from ms_region where level=@level";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("level", level);
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            List<ms_region> rglist = new List<ms_region>();
            while (rd.Read())
            {
                ms_region region = new ms_region();
                region.id = rd["id"].ToString();
                region.name = rd["name"].ToString();
                region.level = rd["level"].ToString();
                rglist.Add(region);
            }
            rd.Close();
            return rglist;

        }
        /// <summary>
        /// 通过父级ID查城市
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static List<ms_region> Querybyprid(string prid)
        {
            string sql = "select * from ms_region where parent_id=@parent_id";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("parent_id", prid);
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            List<ms_region> rglist = new List<ms_region>();
            while (rd.Read())
            {
                ms_region region = new ms_region();
                region.id = rd["id"].ToString();
                region.name = rd["name"].ToString();
                region.level = rd["level"].ToString();
                rglist.Add(region);
            }
            rd.Close();
            return rglist;
        }
    }
}
